<template>
  <div class="login">
    <div class="content">
      <h1>后台管理系统</h1>
      <!-- 用户名登陆 、 手机号登陆 -->
      <el-tabs type="border-card" stretch class="el-tabs" v-model="tabsName">
        <el-tab-pane name="usernumber">
          <template #label>
            <el-icon><UserFilled /></el-icon>
            <span>用户名登陆</span>
          </template>
          <LoginUserVue ref="loginUserRef"></LoginUserVue>
        </el-tab-pane>
        <el-tab-pane name="userphone">
          <template #label>
            <el-icon><Phone /></el-icon>
            <span>手机号登陆</span>
          </template>
          <LoginPhoneVue ref="loginPhoneRef"></LoginPhoneVue>
        </el-tab-pane>
      </el-tabs>
      <!-- 记住密码、忘记密码、登陆 -->
      <div class="login-select">
        <el-checkbox v-model="remeberPassword">记住密码</el-checkbox>
        <el-link type="primary">忘记密码</el-link>
      </div>
      <el-button type="primary" class="login-commit" @click="logInNow"
        >立即登陆</el-button
      >
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import LoginUserVue from './cpns/LoginUser.vue'
import LoginPhoneVue from './cpns/LoginPhone.vue'
export default defineComponent({
  name: 'login',
  components: { LoginUserVue, LoginPhoneVue },
  setup() {
    let remeberPassword = ref<boolean>(true)
    let tabsName = ref<string>('usernumber')
    let loginUserRef = ref<InstanceType<typeof LoginUserVue>>()
    let loginPhoneRef = ref<InstanceType<typeof LoginPhoneVue>>()
    const logInNow = () => {
      if (tabsName.value === 'usernumber') {
        // console.log('打印用户')
        loginUserRef.value?.loginUserAction(remeberPassword.value)
      } else {
        // console.log('手机===')
        loginPhoneRef.value?.loginPhoneAction()
      }
    }
    return {
      remeberPassword,
      tabsName,
      logInNow,
      loginUserRef,
      loginPhoneRef
    }
  }
})
</script>

<style scoped lang="less">
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background-size: cover;
  background: url('../../assets/img/login-bg.jpg') center center;

  .content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin-top: -100px;
    h1 {
      text-align: center;
    }
    .el-tabs {
      width: 320px;
      .el-icon,
      span {
        vertical-align: middle;
      }
    }
    .login-select {
      display: flex;
      margin-top: 5px;
      color: yellowgreen;
      justify-content: space-between;
    }
    .login-commit {
      margin-top: 10px;
      width: 100%;
    }
  }
}
</style>
